<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/1/7 0007
 * Time: 下午 3:00
 */
namespace api\controllers;

use common\services\config\Config;
use common\services\WXLogin\WeiXinLoginService;
use common\services\WechatService;

class WechatController extends BaseController{

    public function actionWechat()
    {
        $WXCode = trim($this->request->post('code'));
        $WXService = new WeiXinLoginService();
        if(empty($WXCode)){
            $WXService = new WeiXinLoginService();
            $WXService->getWeiXinCode();
        }
        $result = $WXService->getWeiXinUserOpenId($WXCode);
        if(!empty($result->access_token) && !empty($result->openid) && !empty($result->refresh_token)){
            $WechatUser = $WXService->getUnionID($result->access_token, $result->openid, $result->refresh_token);
        }
    }

    public function actionTest()
    {
        $auth = new WechatService();
//        $a = $auth->wechat();
        $auth->oauthCallback();
    }

}